package cn.formal.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2 //启用swagger2
public class Swagger2Config {

    @Bean
    public Docket createRestApi(){

        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("搜索服务") //api标题
                .description("搜索服务相关接口描述") //api描述
                .version("1.0.0") //版本号
                .build();

        return new Docket(DocumentationType.SWAGGER_2)//文档类型
        .apiInfo(apiInfo) //设置包含在json ResourceListing响应中的api元信息
        .select() //启动用于api选择的构建器
        .apis(RequestHandlerSelectors.basePackage("cn.formal.controller")) //设置要扫描接口所在的包
        .paths(PathSelectors.any()) //路径过滤器（扫描所有路径）
        .build();
    }
}
